package com.day11.test5_jdk8_date;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Period;

/**
 * @author 小坡
 * @date 2022/9/14  16:36
 **/
public class TestDate {
    public static void main(String[] args) {
//        public static Period between(开始时间,结束时间)计算两个"时间"的间隔
        LocalDate localDate1 = LocalDate.of(2022, 9, 14);
        LocalDate localDate2 = LocalDate.of(2099, 12, 15);
        Period between = Period.between(localDate1, localDate2);
        System.out.println(between);   ///P77Y3M1D     Period对象 77年 3月  1天


//         public int getYears()获得这段时间的年数
        System.out.println(between.getYears());
//         public int getMonths()获得此期间的月数
        System.out.println(between.getMonths());
//        public int getDays()获得此期间的天数
        System.out.println(between.getDays());


//        public long toTotalMonths() 获取此期间的总月数
        System.out.println("这个期间一共是" + between.toTotalMonths() + "个月");


    }
}
